<template>
  <view class="cart-bar">
    <view class="cart-icon-box" @tap="toggleCart">
      <view class="cart-icon">
        <uni-icons type="cart-filled" size="28" color="#fff"></uni-icons>
        <view v-if="totalCount > 0" class="cart-badge">{{ totalCount }}</view>
      </view>
      <view class="cart-price-box">
        <text class="total-price">¥{{ totalPrice.toFixed(1) }}</text>
        <text class="delivery-fee-text">配送费¥{{ deliveryFee }}</text>
      </view>
    </view>
    
    <view 
      class="checkout-btn"
      :class="{ disabled: totalPrice < minPrice }"
      @tap="checkout"
    >
      <text v-if="totalPrice < minPrice">
        还差¥{{ (minPrice - totalPrice).toFixed(1) }}起送
      </text>
      <text v-else>去结算</text>
    </view>
  </view>
</template>

<script setup lang="ts">
interface Props {
  totalCount: number;
  totalPrice: number;
  deliveryFee: number;
  minPrice: number;
}

const props = defineProps<Props>();

const emit = defineEmits(['toggle-cart', 'checkout']);

const toggleCart = () => {
  if (props.totalCount === 0) return;
  emit('toggle-cart');
};

const checkout = () => {
  emit('checkout');
};
</script>

<style scoped>
.cart-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100rpx;
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 0 30rpx;
  box-shadow: 0 -4rpx 12rpx rgba(0,0,0,0.05);
  z-index: 100;
}

.cart-icon-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 20rpx;
}

.cart-icon {
  position: relative;
  width: 80rpx;
  height: 80rpx;
  background-color: #00C853;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-badge {
  position: absolute;
  top: -10rpx;
  right: -10rpx;
  background-color: #ff3b30;
  color: #fff;
  font-size: 20rpx;
  padding: 4rpx 8rpx;
  border-radius: 20rpx;
  min-width: 32rpx;
  text-align: center;
}

.cart-price-box {
  display: flex;
  flex-direction: column;
  gap: 4rpx;
}

.total-price {
  font-size: 32rpx;
  color: #333;
  font-weight: bold;
}

.delivery-fee-text {
  font-size: 22rpx;
  color: #999;
}

.checkout-btn {
  padding: 20rpx 50rpx;
  background-color: #00C853;
  color: #fff;
  font-size: 28rpx;
  font-weight: bold;
  border-radius: 40rpx;
}

.checkout-btn.disabled {
  background-color: #ccc;
}
</style>